package com.moshme.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.moshme.common.annotation.Log;
import com.moshme.common.constant.FeiJuProject;
import com.moshme.common.core.controller.BaseController;
import com.moshme.common.core.domain.AjaxResult;
import com.moshme.common.core.domain.entity.SysUser;
import com.moshme.common.core.page.PageDomain;
import com.moshme.common.core.page.TableDataInfo;
import com.moshme.common.core.page.TableSupport;
import com.moshme.common.enums.BusinessType;
import com.moshme.common.exception.ServiceException;
import com.moshme.common.utils.StringUtils;
import com.moshme.project.domain.*;
import com.moshme.project.service.FileService;
import com.moshme.project.service.ProjectStepService;
import com.moshme.project.service.StageCheckFileService;
import com.moshme.project.service.StageConstructService;
import com.moshme.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Kieyfr
 * @version 1.0
 * @description 验收阶段接口
 * @date 2023/8/29 10:21
 */
@RestController
@RequestMapping("stageCheck")
@Api("验收阶段")
public class StageCheckController extends BaseController {
    @Autowired
    private StageCheckFileService stageCheckFileService;

    /**
     * 获取验收文件列表
     *
     * @param projectId
     * @return
     */
    @GetMapping
    @ApiOperation(value = "验收阶段获取验收阶段")
    public AjaxResult getStageCheckFile(Long projectId){
        LambdaQueryWrapper<StageCheckFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<StageCheckFile> eq = lambdaQueryWrapper.eq(StageCheckFile::getProjectId, projectId);
        StageCheckFile stageCheckFile = stageCheckFileService.getOne(eq);
        List<String> fileList = new ArrayList<>();
        if (stageCheckFile!=null){
            fileList = stageCheckFile.getFileList();
        }
        return success(fileList);
    }

    /**
     * 上传文件
     *
     * @param file
     * @param projectId
     * @return
     */
    @PostMapping("upload")
    @ApiOperation(value = "验收阶段上传文件")
    public AjaxResult upload(MultipartFile file, Long projectId){
        List<String> fileList = stageCheckFileService.upload(file, projectId);
        return success(fileList);
    }

    /**
     * 删除文件
     *
     * @param projectId
     * @param path
     * @return
     */
    @DeleteMapping("delFile")
    @ApiOperation(value = "验收阶段删除文件")
    public AjaxResult delFile(Long projectId,String path){
        if (stageCheckFileService.delFile(projectId,path)){
            return success("删除成功");
        }
        return error("删除失败");
    }

    /**
     * 删除全部文件
     *
     * @param projectId
     * @return
     */
    @DeleteMapping("delAllFile")
    @ApiOperation(value = "验收阶段删除文件")
    public AjaxResult delAllFile(Long projectId){
        if (stageCheckFileService.delAllFile(projectId)){
            return success("删除成功");
        }
        return error("删除失败");
    }





}
